#pragma once
#include "Log.h"

namespace dsth {

class Event {
public:
    Event() {
        handle_ = ::CreateEvent(0, FALSE, FALSE, NULL);
        if (handle_ == NULL) {
            LOG_FATAL("CreateEvent failed.");
        }
    }

    ~Event() {
        ::CloseHandle(handle_);
    }

    void Notify() {
        ::SetEvent(handle_);
    }

    void Nonsignal() {
        ::ResetEvent(handle_);
    }

    void Wait() {
        ::WaitForSingleObject(handle_, INFINITE);
    }

private:
    HANDLE handle_;
};

} // namespace
